/**
  cl /Ox /MD /std:c++17 /EHsc /wd4819 /wd4828 /source-charset:utf-8 /execution-charset:gbk /I ./src/ ./src/test_compensation.cpp /Fo:./build/msvc/release/test_compensation.obj /link /LIBPATH:D:/opt/vcpkg/installed/x86-windows/lib /LIBPATH:./build/msvc/release/ /out:./build/msvc/release/test_compensation.exe
*/
#include <string>
#include <vector>
#include <cassert>
#include <cstdio>
#include <iostream>

#include "compensation.h"

// GP2 Interface
#include <IGeoProbeBase.h>
#pragma comment(lib, "IGdbms2.lib")
#pragma comment(lib, "compensation.lib")

int main(int argc, char* argv[])
{
  COMPENSASION_PARAMS params;
  params.fc_X = "姿态X分量";
  params.fc_Y = "姿态Y分量";
  params.fc_Z = "姿态Z分量";
  params.mag_uncompensated = "未补磁总场";

  params.mag_uncompensated_lp  = "未补磁低通2";
  params.mag_uncompensated_hp  = "未补磁高通2";

  params.mag_compensation      = "补偿值2";
  params.mag_compensated_hp    = "已补磁高通2";
  params.mag_compensated_total = "已补磁总场2";

  params.json_coef_file = "compensation.json";

  char * json_filename;
  char* gdb_filename; // = (char*)"Y12实测数据库.gdb";
  if (argc > 1) {
    gdb_filename = argv[1];
  }  else {
    std::cout << argv[0] << " <gdb_filename> <json_filename>" << std::endl;
    return -1;
  }

  if (argc > 2) {
    json_filename = argv[2];
    params.json_coef_file = json_filename;
  }  else {
    std::cout << argv[0] << " <gdb_filename> <json_filename>" << std::endl;
    return -1;
  }

  HANDLE hGDB = NULL;
  printf("Read from GDB: %s.\n", gdb_filename);
  printf("json filename = %s.\n", json_filename);
  OpenGDB(hGDB, gdb_filename, GP_OpenMode_ReadWrite);
  if (!hGDB) {
    printf("failed call OpenGDB: %s.\n", gdb_filename);
    return -1;
  }
  gdb_compensate(hGDB, &params);
  CloseGDB(hGDB);
  printf("Write to GDB: %s.\n\n", gdb_filename);

  return 0;
}